package org.freemarker.web.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.freemarker.core.model.Car;
import org.freemarker.core.service.CarService;
import org.freemarker.web.custom.CustomHttpServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

@Controller
public class CarListController extends CustomHttpServlet {
	private static final long serialVersionUID = 7353993026767499868L;
	
	@Autowired
	private CarService carService;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		
		
		List<Car> cars = carService.findAll();
		req.setAttribute("carImgFolder", "spring/resources/images/cars");
		req.setAttribute("cars", cars);
		req.getRequestDispatcher("views/car/listCars.ftl").forward(req, res);
	}
}
